package com.demo.utils;

import org.apache.http.HttpEntity;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.util.EntityUtils;
import sun.applet.Main;

import javax.sound.midi.Soundbank;
import java.io.IOException;
import java.util.UUID;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;

/**
 * Create with Intellij idea
 * User:鲁智明
 * Date:2018/9/21
 * Time:15:51
 */
public class HttpClientUtils {

    public static void main(String[] args) throws IOException {
        //get("http://www.baidu.com/");
        System.out.println(HttpClientUtils.getToken());
    }
    public static void get(String url) throws IOException {
        //创建一个默认连接
        CloseableHttpClient httpClient =HttpClients.createDefault();
        //get 请求
        HttpGet httpGet=new HttpGet(url);
        //执行get请求
        CloseableHttpResponse response =httpClient.execute(httpGet);
        //获取状态码
        int statusCode=response.getStatusLine().getStatusCode();
        if(statusCode==200){
            HttpEntity httpEntity=response.getEntity();
            String result=EntityUtils.toString(httpEntity,"UTF-8");
            System.out.println("result："+result);
        }
    }

    public static void post(){
        StringBuffer stringBuffer = new StringBuffer();
        ScheduledExecutorService scheduledExecutorService=Executors.newScheduledThreadPool(5);


    }
    //生成不重复的id
    public static String getToken(){
        return UUID.randomUUID().toString();
    }

}
